import { 头盔, 手枪, 防弹衣, 突击步枪, 冲锋枪, 射手步枪, 栓动步枪, 轻机枪, 霰弹枪, 卡宾枪, 投掷物, 子弹, 药品, 食物, ItemData, } from "../Datas/Data";
import { ColorHex, Constant, ItemType } from "../Framework/Const/Constant";
import AudioManager from "../Framework/Managers/AudioManager";
import { BundleManager, Bundles } from "../Framework/Managers/BundleManager";
import { UIManager } from "../Framework/Managers/UIManager";
import NodeUtil from "../Framework/Utils/NodeUtil";
import { ResourceUtil } from "../Framework/Utils/ResourceUtil";

const { ccclass, property } = cc._decorator;

@ccclass
export default class SpecialSkinItem extends cc.Component {

    Background: cc.Sprite = null;
    Icon: cc.Sprite = null;
    Name: cc.Label = null;
    Bottom: cc.Node = null;

    data: ItemData;

    protected onLoad(): void {
        this.Background = NodeUtil.GetComponent("Background", this.node, cc.Sprite);
        this.Icon = NodeUtil.GetComponent("Icon", this.node, cc.Sprite);
        this.Name = NodeUtil.GetComponent("Name", this.node, cc.Label);
        this.Bottom = NodeUtil.GetNode("Bottom", this.node);
    }

    Init(data) {
        this.data = data;

        this.Name.string = `${data.Name}`;
        BundleManager.LoadSpriteFrame(Bundles.Item, `GunBG_${data.Name}`).then((sf: cc.SpriteFrame) => {
            this.Background.spriteFrame = sf;
        });

        BundleManager.LoadSpriteFrame(Bundles.Item, `${data.Type}_${data.Name}`).then((sf: cc.SpriteFrame) => {
            this.Icon.spriteFrame = sf;
        });

        let color = new cc.Color();
        let scale = 1.5;
        if (data.Name == `AX50-龙影`) {
            cc.Color.fromHEX(color, ColorHex.RED);
        }

        if (data.Name == `FAL-赛博涂鸦`) {
            cc.Color.fromHEX(color, ColorHex.PURPLE);
        }

        if (data.Name == `MPX-白金之星`) {
            cc.Color.fromHEX(color, ColorHex.GOLD);
        }

        if (data.Name == `G18C-矩形几何`) {
            cc.Color.fromHEX(color, ColorHex.BROWN);
            scale = 0.8;
        }

        this.Icon.node.setScale(-scale, scale);
        this.Bottom.color = color;
    }

    OnButtonClick() {
        AudioManager.PlayAudio(Constant.Audio.ButtonClick);
        UIManager.Instance.ShowPanel(Constant.Panel.SpecialSkinDetailPanel, [this.data]);
    }

}
